package com.um.jdy.common.member.service.impl;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import com.um.springboot.starter.code.CommonCode;
import com.um.springboot.starter.exception.ServiceException;

import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import com.um.springboot.starter.orm.service.BaseEntityServiceImpl;
import com.um.jdy.common.member.service.MemberUserService;
import com.um.jdy.common.member.dao.MemberUserDao;
import com.um.jdy.common.member.entity.po.MemberUser;

/**
 * 服务实现类：用户表
 */
@Service
@Slf4j
public class MemberUserServiceImpl extends BaseEntityServiceImpl<MemberUserDao,MemberUser>  implements MemberUserService {

    @Override
    public MemberUser get() {
        SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
        if(!tokenInfo.isLogin){
            return new MemberUser();
        }
        MemberUser user = getEntity(tokenInfo.getLoginId().toString());
        if(null == user){
            return new MemberUser();
        }
        return user;
    }


    /**
     * 保存省市区
     * @param province
     * @param city
     * @param area
     */
    @Override
    public void saveLocation(MemberUser user,String province,String city,String area){
        MemberUser updateUser = new MemberUser();
        updateUser.setMemberUserId(user.getMemberUserId());
        updateUser.setProvince(province);
        updateUser.setCity(city);
        updateUser.setArea(area);
        dao.save(updateUser);
    }

}
